 class QuadraticEquationSolver {
    private double a;
    private double b;
    private double c;

    public QuadraticEquationSolver(double a, double b, double c) {
        if (a == 0) {
            throw new IllegalArgumentException("系数 a 为 0无法构成一元二次方程");
        }
        this.a = a;
        this.b = b;
        this.c = c;
    }

    public void solve() {
        double discriminant = b * b - 4 * a * c;
        if (discriminant > 0) {
            double root1 = (-b + Math.sqrt(discriminant)) / (2 * a);
            double root2 = (-b - Math.sqrt(discriminant)) / (2 * a);
            System.out.println("方程有两个不同实根： " + root1 + " 和 " + root2);
        } else if (discriminant == 0) {
            double root = -b / (2 * a);
            System.out.println("方程有且只有一个实根： " + root);
        } else {
            System.out.println("方程没有实根");
        }
    }

    public static void main(String[] args) {
        try {
            QuadraticEquationSolver solver = new QuadraticEquationSolver(1, -3, 2);
            solver.solve();
        } catch (IllegalArgumentException e) {
            System.out.println(e.getMessage());
        }
    }
}